package com.eight.travel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.travel.dao.AdminMapper;
import com.eight.travel.pojo.Admin;
import com.eight.travel.pojo.User;
import com.eight.travel.service.AdminService;
import com.eight.travel.utils.BaseResp;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Q小旭
 * @version 1.0
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Resource
    AdminMapper adminMapper;


    @Override
    public BaseResp findAll(Integer page, Integer size) {
        //声明分页条件
        Page<Admin> of = Page.of(page,size);
        Page<Admin> adminPage = adminMapper.selectPage(of, null);
        return new BaseResp().SUCCESS("查询成功",adminPage,(int)adminPage.getTotal());
    }

    @Override
    public BaseResp deleteById(Admin admin) {
        int i = adminMapper.deleteById(admin.getAdminid());
        if (i > 0 ){
            return new BaseResp().SUCCESS("删除成功",null,null);
        }
        return new BaseResp().FAIL("删除失败");
    }

    @Override
    public Admin findByUname(String name) {
        QueryWrapper<Admin> adminQueryWrapper = new QueryWrapper<>();
        QueryWrapper<Admin> adminname = adminQueryWrapper.eq("adminname",name);
        return adminMapper.selectOne(adminname);
    }
}
